/*
# ------------------------------------------------------------------------
# JA Cpanel module for Joomla 1.5
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license - PHP files are GNU/GPL V2. CSS / JS are Copyrighted Commercial,
# bound by Proprietary License of JoomlArt. For details on licensing, 
# Please Read Terms of Use at http://www.joomlart.com/terms_of_use.html.
# Author: JoomlArt.com
# Websites:  http://www.joomlart.com -  http://www.joomlancers.com
# Redistribution, Modification or Re-licensing of this file in part of full, 
# is bound by the License applied. 
# ------------------------------------------------------------------------
*/

var JACPanel = new Class({
	initialize: function(cpid, options){
		this.options = Object.extend({
			width: 0,
			height: 0,
			dir: 'down',
			status: 'hide',
			duration: 400
		}, options || {});
		this.cpanel = $(cpid);
		this.cpanel_switcher = $(cpid+'-switcher');
		if (!this.cpanel || !this.cpanel_switcher) return;
		if (!this.options.width) this.options.width = this.cpanel.offsetWidth;
		if (!this.options.height) this.options.height = this.cpanel.offsetHeight;
		this.cpanel.setStyles ({
			'height': this.options.height,
			'width': this.options.width,
			'overflow': 'hidden'
		});
		
		this.status = Cookie.get ('jacpanel-'+cpid);
		if (!this.status) this.status = this.options.status;
		if (this.status == 'hide') {
			if (this.options.dir=='down' || this.options.dir=='up') {
				this.cpanel.setStyle ('height', 0);
			} else {
				this.cpanel.setStyle ('width', 0);
			}
			this.cpanel_switcher.addClass('show');
		} else
			this.cpanel_switcher.addClass('hide');
		
		this.fx = new Fx.Styles (this.cpanel, {'duration': this.options.duration});
		
		this.cpanel_switcher.addEvent ('click', function(){
			if (this.status == 'hide') {
				this.status = 'show';
				this.fx.stop();
				var obj = {};
				if (this.options.dir=='down' || this.options.dir=='up') {
					obj.height = [0, this.options.height];
				} else {
					obj.width = [0, this.options.width];
				}
				obj.opacity = [0,1];
				this.fx.start (obj);
				this.cpanel_switcher.removeClass ('show');
				this.cpanel_switcher.addClass ('hide');
			} else {
				this.status = 'hide';
				this.fx.stop();
				var obj = {};
				if (this.options.dir=='down' || this.options.dir=='up') {
					obj.height = [this.options.height, 0];
				} else {
					obj.width = [this.options.width, 0];
				}
				obj.opacity = [1, 0];
				this.fx.start (obj);
				this.cpanel_switcher.removeClass ('hide');
				this.cpanel_switcher.addClass ('show');
			}
			return false;
		}.bind(this));
		this.cpanel.setStyle('visibility', 'visible');
	}
	
});